package com.ruoyi.kafka.controller;

import com.alibaba.fastjson2.function.FieldSupplier;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.kafka.domain.OrderCreatedEvent;
import com.ruoyi.kafka.kafka.OrderProducer;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;

/**
 * @ClassName OrderController
 * @Description 测试 控制层
 * @Author li yang
 * @Date 2025/9/18 17:10
 * @Version 1.0
 */
@RestController
@RequestMapping("/orders")
@RequiredArgsConstructor
public class OrderController {

    private final OrderProducer producer;

    /**
     * 创建订单 触发消息发送
     *
     * @param id      订单ID
     * @param amount  金额
     * @return
     */
    @PostMapping("/create")
    public AjaxResult create(@RequestParam String id, @RequestParam BigDecimal amount) {
        producer.send(new OrderCreatedEvent(id, amount));
        return AjaxResult.success();
    }

    public static void main(String[] args) {
        List<String> names = Arrays.asList("Alice", "Bob", "Charlie");
        names.forEach(System.out::println);
    }
}
